import Joi from 'joi'
import Router from 'koa-router'
import { CreateBlog, GetAllBlogByUser, GetBlogList, GetOneBlog } from '../controller'
import idempotent from '../middlewares/redlock'
import validate from '../middlewares/validator'
import { createBlogRule } from './validatorRules'

const router = new Router()
router.prefix('/blog')
router.post('/create', idempotent(), validate(createBlogRule), CreateBlog)
router.get('/getone/:blogid', GetOneBlog) //查询指定博客
router.get('/getlist', validate({ page: Joi.number(), limit: Joi.number() }), GetBlogList) //查询博客列表支持分页
router.get('/getallbyuser/:userid', validate({ page: Joi.number(), limit: Joi.number() }), GetAllBlogByUser) //查询一个用户的所有博客
export default router
